package cn.enilu.flash.bean.exception;


import cn.enilu.flash.bean.vo.front.Ret;
import cn.enilu.flash.bean.vo.front.Rets;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ControllerGlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Ret error(Exception e) {
        e.printStackTrace();
        String errorMessage = "服务处理异常";
        if(e instanceof ApplicationException){
            errorMessage = ((ApplicationException)e).getMessage();
        }
        return Rets.failure(errorMessage);
    }
}
